package com.exam.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.exam.entity.ApiResult;
import com.exam.entity.FillQuestion;
import com.exam.entity.Interview;
import com.exam.entity.Student;
import com.exam.service.InterviewService;
import com.exam.serviceimpl.FillQuestionServiceImpl;
import com.exam.serviceimpl.InterviewServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author wanghuipeng
 * @date 2022/5/11
 * @apiNote
 */

@RestController
@RequestMapping("/interview")
public class InterviewController {

    @Autowired
    private InterviewService interviewService;

    @GetMapping
    public ApiResult findOnlyQuestionId() {

//        LambdaQueryWrapper<Interview> queryWrapper = new LambdaQueryWrapper<>();
        List<Interview> list = interviewService.selectAll();
        System.out.println(list);
        return ApiResultHandler.buildApiResult(200,"查询成功",list);
    }

    @PostMapping
    public ApiResult add(@RequestBody Interview interview) {

        boolean res = interviewService.save(interview);
        if (res) {
            return ApiResultHandler.buildApiResult(200,"添加成功",res);
        }
        return ApiResultHandler.buildApiResult(400,"添加失败",res);
    }

    @PutMapping("/{id}")
    public ApiResult update(@PathVariable int id ,@RequestBody Interview interview) {

//        LambdaQueryWrapper<Interview> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(Interview::getInterviewId,interview.getInterviewId());
//        boolean res = interviewService.update(queryWrapper);

        int res = interviewService.updateRemasks(id,interview.getRemasks());

        if (res==1) {
            return ApiResultHandler.buildApiResult(200,"更新成功",res);
        }
        return ApiResultHandler.buildApiResult(400,"更新失败",res);
    }


}
